package top.yudoge.dogeeditor.db.service

import top.yudoge.dogeeditor.db.ResultSetUtil
import top.yudoge.dogeeditor.db.objects.Schema
import java.sql.Connection

class KingbaseVendorBridge : SQLVendorBridge {
    override fun move(connection: Connection, databaseName: String, schemaName: String) {
        connection.schema = schemaName
    }
    override fun schemaList(connection: Connection, dataSourceIdentifier: String, databaseName: String): List<Schema> {
        val schemas = connection.metaData.getSchemas(databaseName, "%")

        return buildList {
            while (schemas.next()) {
                add(
                    Schema(
                        dataSourceIdentifier,
                        databaseName,
                        ResultSetUtil.getStringValue(schemas, "TABLE_SCHEM")
                    )
                )
            }
        }
    }
}